package com.ev.k3cloudBusiness.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ev.apis.model.DsResultResponse;
import com.ev.framework.utils.R;
import com.ev.k3cloud.entity.*;
import com.ev.k3cloud.enums.K3CloudBaseFormId;
import com.ev.k3cloud.service.K3CloudService;
import com.ev.k3cloudBusiness.service.K3AttachmentService;
import com.ev.k3cloudBusiness.service.K3BDOperatorService;
import com.ev.k3cloudBusiness.vo.K3BDOperatorResultsVo;
import com.ev.k3cloudBusiness.vo.K3BDOperatorWhereVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class K3AttachmentServiceImpl implements K3AttachmentService {
    @Autowired
    K3CloudService k3CloudService;

    @Override
    public String save(K3CloudAttachmentEntity entity) {
        K3CloudTopEntity topEntity = new K3CloudTopEntity();
        K3CloudBillSaveBaseEntity saveBaseEntity = new K3CloudBillSaveBaseEntity();
        saveBaseEntity.setModel(entity);
        topEntity.setFormid(K3CloudBaseFormId.BOS_Attachment.getFormId());
        topEntity.setData(saveBaseEntity);
        return k3CloudService.save(JSON.toJSONString(topEntity));
    }

    @Override
    public String batchSave(List<K3CloudAttachmentEntity> entity) {
        K3CloudTopEntity topEntity = new K3CloudTopEntity();
        K3CloudBillBatchSaveBaseEntity batchSaveBaseEntity = new K3CloudBillBatchSaveBaseEntity();
        K3CloudAttachmentEntity[] attachmentArray = new K3CloudAttachmentEntity[entity.size()];
        batchSaveBaseEntity.setModel(entity.toArray(attachmentArray));
        batchSaveBaseEntity.setIsAutoSubmitAndAudit(false);
        batchSaveBaseEntity.setIsDeleteEntry(false);
        topEntity.setFormid(K3CloudBaseFormId.BOS_Attachment.getFormId());
        topEntity.setData(batchSaveBaseEntity);
        return k3CloudService.batchSave(JSON.toJSONString(topEntity));
    }
}
